﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _018传值_输出_引用_数组_具名_可选参数_6___输出参数_引用类型
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Student stu = null;
            //Console.WriteLine(stu.GetHashCode());
            bool b = StudentFactory.Create("cheche", 20, out stu);
            if (!b)
            {
                Console.WriteLine("请输入正确的数值");
            }

            else
            {
                Console.WriteLine("Student:{0},age is {1}",stu.Nmae,stu.Age);
            }
            Console.WriteLine(stu.GetHashCode());
        }
    }

    class Student
    {

        public int Age { get; set; }
        public string Nmae
        {
            get; set;
        }
    }

    class StudentFactory
    {
        public static bool Create(string stuName, int stuAge, out Student result)
        {
            result = null;
            if (string.IsNullOrEmpty(stuName))
            {
                return false;
            }
            if (stuAge < 20 || stuAge > 80)
            {
                return false;
            }
            result = new Student() { Nmae = stuName, Age = stuAge };
            return true;
        }
    }
}
